package com.mark.web.data.controller.portal;

import com.github.pagehelper.PageInfo;
import com.mark.common.ServerResponse;
import com.mark.web.data.service.IProductService;
import com.mark.web.data.entity.vo.ProductDetailVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: 商品操作前端控制
 * @Author: Mark
 * @CreateDate: 2018/8/14.
 * @Version: 2.0
 * @Copyright : 豆浆油条个人非正式工作室
 */
@RestController
@RequestMapping(value = "/product/")
public class ProductController {

    @Autowired
    private IProductService iProductService;

    //1.根据商品Id查找商品详情
    @PostMapping(value = "product_detail.do")
    public ServerResponse<ProductDetailVo> productDetail(@RequestParam(value = "productId") Integer productId){
        return iProductService.portalGetProductDetail(productId);
    }


    //2.根据商品名，商品种类的Id等信息,分页组合查询
    /**
     *
     * @param keyword ：模糊搜索的关键词
     * @param categoryId ： 商品种类的id
     * @param ownerId ： 发布者的ID
     * @param pageNum ： 页数
     * @param pageSize ： 页的容量大小
     * @param orderBy ： 排序的规则
     * @return
     */
    @PostMapping(value = "product_list.do")
    public ServerResponse<PageInfo> list(@RequestParam(value = "keyword",required = false)String keyword,
                                           @RequestParam(value = "categoryId",required = false)Integer categoryId,
                                           @RequestParam(value = "ownerId",required = false)Integer ownerId,
                                           @RequestParam(value = "pageNum",defaultValue = "1") int pageNum,
                                           @RequestParam(value = "pageSize",defaultValue = "8") int pageSize,
                                           @RequestParam(value = "orderBy",defaultValue = "") String orderBy){
        return iProductService.getProductByKeywordCategory(keyword,ownerId,categoryId,pageNum,pageSize,orderBy);
    }


}
